<?php
defined('_JEXEC') or die( 'Restricted access' );

jimport( 'joomla.application.component.view');

class igcommentViewigcomment extends JView
{
	function display($tpl = null)
	{
		global $mainframe, $option;
		
		$configArray =& JComponentHelper::getParams('com_igallery');
		$moderate = $configArray->get('moderate_comment', 0);
		
	    JToolBarHelper::title( JText::_( 'COMMENTS' ), 'generic.png' );
		JToolBarHelper::publish();
		JToolBarHelper::unpublish();
		
		if( !empty($moderate) )
		{
			JToolBarHelper::custom('moderate', 'tick.png', 'tick.png', JText::_( 'APPROVE' ) );
			JToolBarHelper::custom('unmoderate', 'unmoderate.png', 'unmoderate.png', JText::_( 'UNAPPROVE' ) );
		}
		
		JToolBarHelper::deleteList();
		
		$context = 'igcomment';
		$filter_state		= $mainframe->getUserStateFromRequest( $context.'.filter_state',		'filter_state',		'',				'word' );
		$filter_catid		= $mainframe->getUserStateFromRequest( $context.'.filter_catid',		'filter_catid',		0,				'int' );
		$filter_order		= $mainframe->getUserStateFromRequest( $context.'.filter_order',		'filter_order',		'date',	'cmd' );
		$filter_order_Dir	= $mainframe->getUserStateFromRequest( $context.'.filter_order_Dir',	'filter_order_Dir',	'',				'word' );
		$search				= $mainframe->getUserStateFromRequest( $context.'.search',			'search',			'',				'string' );
		$search				= JString::strtolower( $search );

		$items		= & $this->get( 'Data');
		$total		= & $this->get( 'Total');
		$pagination = & $this->get( 'Pagination' );

		$lists = array();
		$lists['catid'] = igHtmlHelper::getCategorySelect('filter_catid', 'id', 'name', null, true, false, 1, true, $filter_catid);
		
		$lists['state']	= JHTML::_('grid.state',  $filter_state );
		$lists['order_Dir'] = $filter_order_Dir;
		$lists['order'] = $filter_order;
		$lists['search']= $search;
		
		$model = $this->getModel();
		$thumbFiles = array();
		for ($i=0; $i<count($items); $i++)
		{
		    $row =& $items[$i];
		    $category = & $model->getCategory($row->gallery_id);
		    $profile  = & $model->getProfile($category->profile);
		    
		    if(! $thumbFiles[$i] = igFileHelper::originalToResized($row->filename, $profile->thumb_width, 
		    $profile->thumb_height, $profile->img_quality, $profile->crop_thumbs, $row->rotation, $profile->round_thumb, $profile->round_fill) )
		    {
		        return false;
		    }	
		}
		
		$document =& JFactory::getDocument();
		$document->addStyleSheet(IG_HOST.'components/com_igallery/css/toolbar.css');

		$this->assignRef('moderate',	$moderate);
		$this->assignRef('thumbFiles',  $thumbFiles);
		$this->assignRef('lists',		$lists);
		$this->assignRef('items',		$items);
		$this->assignRef('pagination',	$pagination);

		parent::display($tpl);
	}
}